package com.feihong.txgw.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.feihong.txgw.R;
import com.feihong.txgw.model.bean.searchList.HisToryEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @name txgw_app
 * @class name：com.feihong.txgw.adapter
 * @class describe:
 * @author wangziheng
 * @time 2017/11/1 11:46
 * @change
 * @chang time
 * @class describe
 */
public class HotSearchHistoryAdapter extends BaseAdapter {
    private Context mContext;
    private List<HisToryEntity> mData;
    private LayoutInflater mLayoutInflater;
    public HotSearchHistoryAdapter (Context context){
        mContext = context;
        mData = new ArrayList<>();
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    public void setData(List<HisToryEntity> data){
        mData = data;
        notifyDataSetChanged();
    }
    public void clear(){
        if(mData != null){
            mData.clear();
        }
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HistoryViewHolder viewHolder;
        if(convertView == null){
            convertView = mLayoutInflater.inflate(R.layout.item_hotsearch,parent,false);
            viewHolder = new HistoryViewHolder();
            viewHolder.initView(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (HistoryViewHolder) convertView.getTag();
        }
        viewHolder.initData(position);
        return convertView;
    }

    class HistoryViewHolder{
        private TextView mTv;

        public void initView(View convertView){
            mTv = (TextView) convertView.findViewById(R.id.hitstory_tv);
        }

        public void initData(int position){
            mTv.setText(mData.get(position).getHistoryContent());
        }
    }
}
